
#include "AReVi/arSystem.h"
using namespace AReVi;
#include "AReVi/activity.h"

#include "AReVi/Lib3D/viewer3D.h"
#include "AReVi/Lib3D/simpleInteractor.h"
#include "AReVi/Lib3D/object3D.h"
#include "AReVi/Lib3D/viewer3D.h"
#include "AReVi/VRML/vrmlShape3D.h"

//----------------------------------------------------------------------------

ArRef<Scheduler> simulationInit(void) {
    if(ArSystem::getCommandLine().size() < 2) {
        cerr << "usage: " << ArSystem::getCommandLine()[0] << " <model>.wrl" << endl;
        return(Scheduler::nullRef());
    }
    ArRef<Scheduler> sched=RealTimeScheduler::NEW(1e-3);

    ArRef<Object3D> obj=Object3D::NEW();
    obj->setTransient(false); // UGLY !
    ArRef<VrmlShape3D> sh=VrmlShape3D::NEW();
    if (!sh->parseURL(ArSystem::getCommandLine()[1])) {
        cerr << sh->getURL() << endl;
        cerr << sh->readParserMessages() << endl;
    }
    obj->setShape(sh);
    

    ArRef<Viewer3D> view=Viewer3D::NEW();
    view->setCloseAction(Renderer3D::CLOSE_LEAVE);
    ArRef<SimpleInteractor> interactor=SimpleInteractor::NEW();
    interactor->setObjectInteraction(false);
    interactor->setTransient(false); // UGLY !
    interactor->setRenderer(view);

    unsigned int w,h;
    Renderer3D::getScreenSize(w,h);
    view->setWindowGeometry(w-400,0,400,400);
    view->setMapped(true);

    return(sched);
}

int main(int argc, char ** argv) {
    ArSystem arevi(argc,argv);
//    ArSystem::loadPlugin("Imlib2ImageLoader");
    ArSystem::loadPlugin("MagickImageLoader");
    ArSystem::simulationLoop(&simulationInit);
    return(0);
}
